package com.qiangesoft.flowable.controller;

import com.qiangesoft.flowable.constant.R;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 流程待办 控制器
 *
 * @author qiangesoft
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/mine")
    public R mine() {
        // 某人的待办任务：按照时间倒序
        String userId = "zhangsan";
        List<Task> taskList = taskService.createTaskQuery()
//                .processDefinitionKey("")
//                .taskCandidateOrAssigned("")
                .taskAssignee(userId)
                .active()
                .orderByTaskCreateTime().desc()
                .list();
        return R.ok(taskList.toString());
    }

    @GetMapping("/handle")
    public R handle(String taskId) {
        // 完成任务
        taskService.complete(taskId);
        return R.ok();
    }

}
